package com.huawei.mytestapp.slice;

import com.huawei.mytestapp.ResourceTable;
import com.youth.banner.Banner;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Image;
import ohos.agp.components.PositionLayout;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.components.ComponentContainer.LayoutConfig;
import ohos.global.resource.NotExistException;
import ohos.global.resource.Resource;
import ohos.global.resource.ResourceManager;
import ohos.global.resource.WrongTypeException;
import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class MainAbilitySlice extends AbilitySlice {

    private PositionLayout myLayout = new PositionLayout(this);
    Banner banner;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        banner = new Banner(this);
        LayoutConfig config = new LayoutConfig(LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_PARENT);
        myLayout.setLayoutConfig(config);
        ShapeElement element = new ShapeElement();
        element.setShape(ShapeElement.RECTANGLE);
        element.setRgbColor(new RgbColor(255, 255, 255));
        myLayout.setBackground(element);

        List<Integer> list=new ArrayList<>();


        list.add(ResourceTable.Media_b1);
        list.add(ResourceTable.Media_b2);
        list.add(ResourceTable.Media_b3);
        list.add(ResourceTable.Media_4);
        list.add(ResourceTable.Media_5);
        try {
            banner.setImages(list).start();
        } catch (NotExistException e) {
            e.printStackTrace();
        } catch (WrongTypeException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        myLayout.addComponent(banner);

        super.setUIContent(myLayout);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
